/**
 * Created by Baggio on 2018-11-28.
 */
/**
 * Created by Baggio on 2017/3/2.
 */
$(function () {
    $("#userSubmit").click(function () {
        var userName=$("#userName").val();
        var passWord=$("#passWord").val();
        var code=$("#code").val();
        if (userName== '' || userName==undefined) {
            alert("请输入账号！");
            return;
        }
        if (passWord== '' || passWord==undefined) {
            alert("请输入密码！");
            return;
        }
        alert(code);
        if (code== '' || code==undefined) {
            alert("请输入验证码！");
            return;
        }
        console.log("=========#userForm=======>>>>")
console.log($('#userForm').serialize());

        $("#userForm").ajaxSubmit({
            type: "POST",
            url: '/login/login',
            data:$('#userForm').serialize() ,// 你的formid
            dataType:"json",
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.statusText);
                $(".loading").hide();
                alert("Connection error");
            },
            beforeSend: function () {
                console.log("begin...............");
                $(".loading").show();
            },
            success: function (data) {
                console.log(data);
                if (data.code != 1) {
                    alert(data.msg);
                    checkCode();
                    return;
                }
                alert(data.msg);
                window.location.href = "/admin/index"
            },
            complete: function (XMLHttpRequest, textStatus) {
                // alert('远程调用成功，状态文本值：'+textStatus);
                console.log("end...............");
                $(".loading").hide();
            },
        });

    });


    $("#modifyUserSubmit").click(function () {
        if ($("#userName").val() == '') {
            alert("请输入账号！");
            return;
        }

        $("#adminUserForm").ajaxSubmit({
            type: "POST",
            url: '/user/modifyUser',
            data: $('#adminUserForm').serialize(),// 你的formid
            error: function (request) {
                $("#loading").hide();
                alert("Connection error");
            },
            beforeSend: function () {
                console.log("begin...............");
                $(".loading").show();

            },
            success: function (data) {
                console.log(data);
                if (data.code != 1) {
                    alert(data.msg);
                    return;
                }

                alert(data.msg);
            },
            complete: function (XMLHttpRequest, textStatus) {
                // alert('远程调用成功，状态文本值：'+textStatus);
                console.log("end...............");
                $(".loading").hide();
            },
        });

    })
});

function checkCode() {
    $("img").attr("src", "/login/getVerificatioCode?" + new Date().getTime());
}

//回车时，默认是登陆
function on_return(){
    if(window.event.keyCode == 13){
        if (document.all('userSubmit')!=null){
            document.all('userSubmit').click();
        }
    }
}





